package com.cxg.fairy.ec.main.personal.coupon;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.alibaba.fastjson.JSONObject;
import com.cxg.fairy.ec.main.order.PostOrderDelegate;

import java.util.ArrayList;

/**
 * Created by CFairy
 */

public class CouponTabPagerAdapter extends FragmentStatePagerAdapter {

    private final ArrayList<String> TAB_TITLES = new ArrayList<>();

    private CouponTabDelegate mDelegate = null;

    private PostOrderDelegate pDelegate = null;

    private String mPreSubmitOrderId = "";

    public CouponTabPagerAdapter(FragmentManager fm, JSONObject object, String preSubmitOrderId,CouponTabDelegate delegate, PostOrderDelegate postOrderDelegate) {
        super(fm);
        mDelegate = delegate;
        pDelegate = postOrderDelegate;
        mPreSubmitOrderId = preSubmitOrderId;
        final int availableNum = object.getInteger("availableNum");
        final int notAvailableNum = object.getInteger("notAvailableNum");
        TAB_TITLES.add("可用(" + availableNum + ")");
        TAB_TITLES.add("不可用(" + notAvailableNum + ")");
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return CouponListDelegate.create(0,mPreSubmitOrderId,mDelegate,pDelegate);
        } else if (position == 1) {
            return CouponListDelegate.create(1,mPreSubmitOrderId,mDelegate,pDelegate);
        }
        return null;
    }

    @Override
    public int getCount() {
        return TAB_TITLES.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return TAB_TITLES.get(position);
    }
}
